const $api = require('../../utils/api').API
const $cache = require('../../utils/storage')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    type: {
      type: String,
      value: 's1'
    },
    pic: {
      type: String,
      value: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/test.png'
    },
    userPic: {
      type: String,
      value: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/ad2.png'
    },
    pic2: {
      type: String,
      value: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/test2.png'
    },
    userPic2: {
      type: String,
      value: 'https://easeview.oss-cn-shanghai.aliyuncs.com/staticPic/static/ad2.png'
    },
    isGood: {
      type: Boolean,
      value: false
    },
    isCollect: {
      type: Boolean,
      value: false
    },
    title: {
      type: String,
      value: '这里是动态标题文字展示两行，多余不做展6611111112222222222222211113333333333111111111133333336'
    },
    userName: {
      type: String,
      value: '小妮子'
    },
    likeNum: {
      type: Number,
      value: 1.3
    },
    collectNum: {
      type: Number,
      value: 222
    },
    commentNum: {
      type: Number,
      value: 111
    },
    time: {
      type: String,
      value: '2023-8-9 13:00'
    },
    isMyDetail: {
      type: Boolean,
      value: true
    },
    isCare: {
      type: Boolean,
      value: false
    },
    id1: {
      type: String,
      value: ''
    },
    openId: {
      type: String,
      value: ''
    },
    momentId:{
      type:String,
      value:''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {},

  /**
   * 组件的方法列表
   */
  methods: {
    handleCollect() {
      let collectNum = this.data.collectNum
      if (!this.data.isCollect) {
        $api.addStore({
          momentId:this.data.momentId,
          openId:this.data.openId
        })
        collectNum = collectNum + 1
      } else {
        $api.deleteStore({
          momentId:this.data.momentId,
          openId:this.data.openId
        })
        collectNum = collectNum - 1
      }
      this.setData({
        collectNum,
        isCollect: !this.data.isCollect
      })
    },
    handleLike() {
      let likeNum = this.data.likeNum
      if (this.data.isGood) {
        $api.addStore({
          momentId:this.data.momentId,
          openId:this.data.openId
        })
        likeNum = likeNum - 1
      } else {
        $api.deleteLike({
          momentId:this.data.momentId,
          openId:this.data.openId
        })
        likeNum = likeNum + 1
      }
      this.setData({
        likeNum,
        isGood: !this.data.isGood
      })
    },
    handleCare() {
      let myOpenId = $cache._getStorage('openId')
      if(!this.data.isCare){
        $api.detail.focus({
          myOpenId,
          openId:this.data.openId
        })
      }else{
        $api.detail.deleteFocus({
          myOpenId,
          openId:this.data.openId
        })
      }
      this.setData({
        isCare: !this.data.isCare
      })
    },
    goDetail(e) {
      let id = this.data.id1
      let openId = this.data.openId
      wx.redirectTo({
        url: `/pages/detail_new/detail_new?id=${id}&openId=${openId}`,
      })
    },
  }
})